package com.example.healthapp.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.healthapp.R;
import com.example.healthapp.utils.InterfaceTool;

import java.util.HashMap;

// 新闻详情页面的Fragment
public class NewsDetailsActivity extends AppCompatActivity {

    ImageView news_details_back, news_details_img;
    TextView news_details_date, news_details_title, news_details_content, news_details_description, news_details_account;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_details);
        InterfaceTool.setFullScreen(this, true);
        initview();
        refresh();
        event();
    }

    //事件
    private void event() {
        news_details_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void refresh() {
        //详情页面  通过intent传递并获取数据
        HashMap<String, Object> hashMap = (HashMap<String, Object>) getIntent().getSerializableExtra("data");
        news_details_date.setText(hashMap.get("date").toString());
        news_details_title.setText(hashMap.get("title").toString());
        news_details_content.setText(hashMap.get("content").toString());
        news_details_description.setText(hashMap.get("description").toString());
        news_details_account.setText(hashMap.get("content").toString().substring(55, 60));
        Glide.with(NewsDetailsActivity.this)
                .load(hashMap.get("img").toString())
                .into(news_details_img);
    }

    //初始化
    private void initview() {
        news_details_back = findViewById(R.id.news_details_back);
        news_details_description = findViewById(R.id.news_details_description);
        news_details_img = findViewById(R.id.news_details_img);
        news_details_title = findViewById(R.id.news_details_title);
        news_details_content = findViewById(R.id.news_details_content);
        news_details_date = findViewById(R.id.news_details_date);
        news_details_account = findViewById(R.id.news_details_account);
    }
}